import {reqCategoryList,reqrollPlayList,reqFloorList} from '@/api'

const actions ={
    //getCategoryList用户获取三级分类的数据,里面要发AJAX请求
    async getCategoryList({commit}){
        //发送网络请求,获取三级分类数据
        let result=await reqCategoryList()
        if(result.code ===200){
            commit('SAVE_CATEGORY_LIST',result.data.slice(0,15))
        }else{
            alert(result.message)
        }
    },
    async getRollPlayList({commit}){
        let {code,data,message} =await reqrollPlayList()
        if(code===200){
            commit('SAVE_ROLLPLAY_LIST',data)
        }else{
            alert(message)
        }
    },
    async getFloorList({commit}){
        let result = await reqFloorList()
        if(result.code===200){
            commit('SAVE_FLOOR_LIST',result.data)
        }else{
            alert(result.message)
        }
    }
}
const mutations = {
    SAVE_CATEGORY_LIST(state,list){
        state.categoryList=list
    },
    SAVE_ROLLPLAY_LIST(state,list){
        state.rollPlayList=list
    },
    SAVE_FLOOR_LIST(state,list){
        state.floorList=list
    }
}

const state={
    //三级分类数据
    categoryList:[],
    rollPlayList:[],
    floorList:[]
}
const getters ={}

export default{
    state,
    actions,
    mutations,
    getters
}